package com.yserp.project.erp.store.outorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yserp.common.utils.mybatis.MybatisPlusUtil;
import com.yserp.project.erp.common.enums.OutOrderTypeEnums;
import com.yserp.project.erp.store.outorder.domain.OutOrderItem;
import com.yserp.project.erp.store.outorder.domain.OutOrderItemVo;
import com.yserp.project.erp.store.outorder.mapper.OutOrderItemMapper;
import com.yserp.project.erp.store.outorder.service.IOutOrderItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品出库单子Service业务层处理
 *
 * @author yserp
 * @date 2022-07-13
 */
@Service
public class OutOrderItemServiceImpl extends ServiceImpl<OutOrderItemMapper,OutOrderItem> implements IOutOrderItemService {
    @Resource
    private OutOrderItemMapper outOrderItemMapper;


    /**
     * 查询商品出库单子列表
     *
     * @param outOrderItem 商品出库单子
     * @return 商品出库单子
     */
    @Override
    public List<OutOrderItem> selectOutOrderItemList(OutOrderItem outOrderItem) {
        QueryWrapper<OutOrderItem> queryWrapper = new QueryWrapper<>();
        MybatisPlusUtil.notNullField(outOrderItem, queryWrapper);
        return outOrderItemMapper.selectList(queryWrapper);
    }


    @Override
    public List<OutOrderItem> selectOutOrderItemListByMainId(Long id) {
        OutOrderItem outOrderItem = new OutOrderItem();
        outOrderItem.setOutOrderId(id);
        return this.selectOutOrderItemList(outOrderItem);
    }

    @Override
    public List<OutOrderItemVo> selectOutOrderItemListByParam(Long sourceOrderId, String orderType, Long warehouseId) {
        //领用出库
        if(OutOrderTypeEnums.APPLICATION.getCode().equals(orderType)){
            return outOrderItemMapper.selectOutOrderItemListByProductOrder(sourceOrderId,warehouseId);
        }
        //销售出库
        if(OutOrderTypeEnums.SALE.getCode().equals(orderType)){
            return outOrderItemMapper.selectOutOrderItemListBySaleOrder(sourceOrderId,warehouseId);
        }
        return null;
    }

    @Override
    public List<OutOrderItemVo> selectOutOrderItemListByGoodIdAndWarehouseId(Long orderId, Long warehouseId) {
        return outOrderItemMapper.selectOutOrderItemListByGoodIdAndWarehouseId(orderId,warehouseId);
    }
}
